{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a8f606dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "url=\"https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job\"\n",
    "import requests,json\n",
    "payload = {\n",
    "  \"data\": {\n",
    "    \"mainSearchPcConditionForm\": {\n",
    "      \"city\": \"020\",\n",
    "      \"dq\": \"020\",\n",
    "      \"pubTime\": \"\",\n",
    "      \"currentPage\": \"0\",\n",
    "      \"pageSize\": 40,\n",
    "      \"key\": \"产品经理\",\n",
    "      \"suggestTag\": \"\",\n",
    "      \"workYearCode\": \"\",\n",
    "      \"compId\": \"\",\n",
    "      \"compName\": \"\",\n",
    "      \"compTag\": \"\",\n",
    "      \"industry\": \"\",\n",
    "      \"salary\": \"\",\n",
    "      \"jobKind\": \"\",\n",
    "      \"compScale\": \"\",\n",
    "      \"compKind\": \"\",\n",
    "      \"compStage\": \"\",\n",
    "      \"eduLevel\": \"\"\n",
    "    },\n",
    "    \"passThroughForm\": {\n",
    "      \"scene\": \"condition\",\n",
    "      \"skId\": \"9ez6j6csrdoy9nvfutdiew611wbl86va\",\n",
    "      \"fkId\": \"9ez6j6csrdoy9nvfutdiew611wbl86va\",\n",
    "      \"ckId\": \"002ab715d391teewj0kb62c10ewm4k6a\",\n",
    "      \"suggest\": None\n",
    "    }\n",
    "  }\n",
    "}\n",
    "\n",
    "headers = {\n",
    "    'Accept': 'application/json, text/plain, */*',\n",
    "    'Accept-Encoding': 'gzip, deflate, br',\n",
    "    'Accept-Language': 'zh-CN,zh;q=0.9',\n",
    "    'Cache-Control': 'no-cache',\n",
    "    'Connection': 'keep-alive',\n",
    "    'Content-Length': '481',\n",
    "    'Content-Type': 'application/json;charset=UTF-8;',\n",
    "    'Cookie': 'inited_user=7143dbfc8d832652823bd64b1481ca3c; __gc_id=de54ea2e47654f2d9731240061698a42; _ga=GA1.1.1674171972.1681903465; __uuid=1681903464951.45; need_bind_tel=false; c_flag=553813100ff971d55ff0a28712e6c5f4; imClientId=b5e1273d5cb093f4551d85b2fb739565; imId=b5e1273d5cb093f4ff8353f2429edccb; imClientId_0=b5e1273d5cb093f4551d85b2fb739565; imId_0=b5e1273d5cb093f4ff8353f2429edccb; XSRF-TOKEN=54k2xLJTTk6WL5nroz_ALw; __tlog=1685531410515.92%7C00000000%7C00000000%7Cs_o_007%7Cs_o_007; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1685531411; acw_tc=2760829216855314107843808ef2ec3418932673a19a95fb2471b28323472a; UniqueKey=92e8ad0c82debad041344312b1f2ca2b; liepin_login_valid=0; lt_auth=uugPa3ADyF765CXb2GBd4vtKht2oWGWc8HtYhEoAitK%2BWfax4P%2FmQAOHqrUA%2BioIq09ycf4zMLb2MO39yHdO6UsQ%2FVGnlZ6utf6k1XweTuBkHuyflMXuqsjQQ5wtrXo6ykpgn2si0HU%3D; access_system=C; user_roles=0; user_photo=5f8fa3bc8dbe6273dcf85e5e08u.png; user_name=%E6%A2%81%E9%A2%96; new_user=false; inited_user=7143dbfc8d832652823bd64b1481ca3c; imApp_0=1; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1685531485; __session_seq=5; __uv_seq=5; fe_im_socketSequence_new_0=2_2_2; fe_im_opened_pages=; fe_im_connectJson_0=%7B%220_92e8ad0c82debad041344312b1f2ca2b%22%3A%7B%22socketConnect%22%3A%222%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D; _ga_54YTJKWN86=GS1.1.1685531410.5.1.1685531658.0.0.0',\n",
    "    'Host': 'apic.liepin.com',\n",
    "    'Origin': 'https://www.liepin.com',\n",
    "    'Pragma': 'no-cache',\n",
    "    'Referer': 'https://www.liepin.com/',\n",
    "    'sec-ch-ua': '\"Google Chrome\";v=\"113\", \"Not(A:Brand\";v=\"24\", \"Chromium\";v=\"113\"',\n",
    "    'sec-ch-ua-mobile': '?0',\n",
    "    'sec-ch-ua-platform': '\"macOS\"',\n",
    "    'Sec-Fetch-Dest': 'empty',\n",
    "    'Sec-Fetch-Mode': 'cors',\n",
    "    'Sec-Fetch-Site': 'same-site',\n",
    "    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',\n",
    "    'X-Client-Type': 'web',\n",
    "    'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}',\n",
    "    'X-Fscp-Fe-Version': '',\n",
    "    'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}',\n",
    "    'X-Fscp-Trace-Id': 'bac7ee17-48c8-4496-8b97-b4d4868fcaed',\n",
    "    'X-Fscp-Version': '1.1',\n",
    "    'X-Requested-With': 'XMLHttpRequest',\n",
    "    'X-XSRF-TOKEN': '54k2xLJTTk6WL5nroz_ALw'\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d78ddf98",
   "metadata": {},
   "source": [
    "# 数据整理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aee99e9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'产品经理'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = payload['data']['mainSearchPcConditionForm']['key']\n",
    "key"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b44faeba",
   "metadata": {},
   "source": [
    "# 数据储存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f3559f62",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "632f6e17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2023, tm_mon=6, tm_mday=8, tm_hour=14, tm_min=56, tm_sec=21, tm_wday=3, tm_yday=159, tm_isdst=0)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2d5bfc09",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2693257046.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\ASUS\\AppData\\Local\\Temp\\ipykernel_19556\\2693257046.py\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m    output_time\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "output_time = str(time.localtime().tm_mon)\\\n",
    "             +str(time.localtime().tm_mday)+'_'\\\n",
    "             +str(time.localtime().tm_hour)\\\n",
    "             +str(time.localtime().tm_min)\\\n",
    "output_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9082d962",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'df' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_19556\\3008173459.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_excel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m'_liepin_'\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m'.xlsx'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'df' is not defined"
     ]
    }
   ],
   "source": [
    "df.to_excel(key+'_liepin_'+key+'.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6531ea50",
   "metadata": {},
   "source": [
    "# 数据分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b551660",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb4fafd0",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_excel('liepin_'+key+output_time+'.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b23febf",
   "metadata": {},
   "source": [
    "# 数据分析列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d23797dc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c35c7e9c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63ecbf82",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "481c9a78",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8801c5fc",
   "metadata": {},
   "source": [
    "# 广州PM分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef288158",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11a46a7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "上海_岗位个数 = df_PM_sh['job.dq'].values_counts().values.tolist()[1:]\n",
    "上海_岗位个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36247578",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install pycharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d52a8e37",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 可视化：以可视化工具数据形态符合的数据进行输入\n",
    "\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    Map()\n",
    "    .add(\"商家A\", [list(z) for z in zip(上海地区,上海岗位个数)], \"上海\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"Map-上海地图\"), visualmap_opts = opts.VisualMapOpts()\n",
    "    )\n",
    ")\n",
    "\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62b7cab7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bb0e6e6c",
   "metadata": {},
   "source": [
    "# job.labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e26585de",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7e85804",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "792b22b3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "580fc60b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 可视化词云图\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.globals import SymbolType\n",
    "\n",
    "\n",
    "c = (\n",
    "    WordCloud()\n",
    "    .add(\"\", PM_labels_words, word_size_range=[20, 100], shape=SymbolType.DIAMOND)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"WordCloud-shape-diamond\"))\n",
    "    .render(\"wordcloud_diamond2.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "485dfd1e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
